package com.tnsw.noxnox.db;

import java.util.ArrayList;

import android.test.UiThreadTest;
import android.util.Log;

public class DBManagerInterfaceDispatcher implements DBManagerInterface {

	private String tag = "DBManagerInterfaceDispatcher";
	private ArrayList<DBManagerInterface> arrDbi;
	
	public DBManagerInterfaceDispatcher() {
		this.arrDbi = new ArrayList<DBManagerInterface>();
	}
	
	@Override
	public void onSQLExecuted(DBManager sender, String command, String tableName) {
		int len = this.arrDbi.size();
		int i;
		for (i = 0; i < len; i++) {
			DBManagerInterface dbi = this.arrDbi.get(i);
			dbi.onSQLExecuted(sender, command, tableName);
		}
	}
	
	public void register(DBManagerInterface dbi) {
		if (this.arrDbi.contains(dbi) == false) {
			this.arrDbi.add(dbi);	
		}
		
		Log.d(tag, "After registered, size()=" + this.arrDbi.size());
	}
	
	protected void unregister(DBManagerInterface dbi) {
		this.arrDbi.remove(dbi);
	}

}
